<?php
declare (strict_types = 1);

namespace app\api\controller;

use app\BaseController;
use think\facade\View;

class Base extends BaseController
{
    //封装模板渲染函数
    public  function fetch($tpl="")
    {
        if($tpl){
            return  View::fetch($tpl);
        } else {
            return View::fetch();
        }
    }

    //封装模型变量输出
    public function assign($name,$data){

        return View::assign($name, $data);

    }

    //门户token验证
    public function checktoken($token=""){

        $uuid = uuid();
        $arr = array(
            "REQUEST"=>array(
                "HEAD"=>array(
                    "ACCOUNT"=>"",
                    "BIZTRANSACTIONID"=> "PMS_".date("YmdHis")."_".rand(),
                    "CONSUMER"=> 1,
                    "COUNT"=> 1,
                    "MODULE"=> "",
                    "PAGENUM"=> "",
                    "PAGESIZE"=> "",
                    "PASSWORD"=> "",
                    "SRVLEVEL"=> 1
                ),
                "LIST"=>array(
                     "ITEM"=>array(
                         "ACCESSTOKEN"=>$token,
                         "SYSID"=>"10001",
                         "UUID"=>$uuid,
                     )
                )
            )

        );
        $xmldata = arr2xml($arr,false);
        try {

            $wsdl = "http://127.0.0.1:9001/WP_CQP_SOA/APP_DESK_SERVICES/Proxy_Services/IDM_USER_01_GetUserInfo_PS?wsdl";
            $xml  = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:idm="http://www.cq-p.com.cn/IDM_USER_01_GetUserInfo">';
            $xml .= "<soapenv:Header/>
					   <soapenv:Body>
						  <idm:IDM_USER_01_GetUserInfo>
						      <idm:DATA><![CDATA[".$xmldata."]]></idm:DATA>
                          </idm:IDM_USER_01_GetUserInfo>
					   </soapenv:Body>
					</soapenv:Envelope>";
            $arr_header[] = "Content-type: text/xml"; //使用xml格式传递
            $arr_header[] = 'SOAPAction:http://127.0.0.1/IDM_USER_01_GetUserInfo'; //添加swdl的方法

            $result = http_request_xml($wsdl, $xml, $arr_header);

            $result = xmltoarray($result);
            return $result;

        } catch (\Exception $e) {
            $error = ["status"=>false,"msg"=>$e->getMessage(),"code"=>$e->getCode()];
            return $error;
        }

    }

}
